﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace WebApiMIT3.BusinessLayer
{
    public static class DataTrafficHelper
    {
        private const string SearchExtension = "*.*";
        private const char SplitCharactor = '|';

        public static async Task DeleteAllFilesInDir(string path)
        {
            await Task.Run(() =>
            {
                FileInfo[] dir = new DirectoryInfo(path).GetFiles(SearchExtension, SearchOption.TopDirectoryOnly);

                if (dir != null)
                {
                    if (dir.Any())
                    {
                        foreach (FileInfo file in dir)
                        {
                            file.Delete();
                        }
                    }
                }
            });
        }

        public static async Task<List<string>> GetCategories(string categoryList)
        {
            var categories = new List<string>();

            await Task.Run(() =>
            {
                if (categoryList != null)
                {
                    categories.AddRange(categoryList.Split(SplitCharactor));
                }
            });
            return categories;
        }
    }
}